package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//出现异常,执行
public class NcExceptionHandler {
//    自定义异常
    @ExceptionHandler({
        //指定你要处理的异常
    NcException.class
})
    public Result handlerCustomException(NcException e){
        e.printStackTrace();
        return Result.errorCodeMessage(e.getCode(),e.getMessage());
    }

    //    其他异常
    @ExceptionHandler({
            Exception.class
    })
    public Result handlerCustomException(Exception e){
        e.printStackTrace();
        return Result.errorCodeMessage(500,"系统异常请联系管理员");
    }
}
